package com.estar.assistsurvy.widget;


import com.estar.assistsurvy.R;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;

public class TaskOperationPopwindow extends PopupWindow {
	private Button caseCancel,caseStop,cancel,reBroadcast;
	private TextView caseTitle;
	private View v;
	public TaskOperationPopwindow(Context context,OnClickListener cancelClick,OnClickListener stopClick,OnClickListener reBroadcastClick,int caseState){
		super(context);
		LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		v=inflater.inflate(R.layout.popwindow_task, null);
		caseCancel=(Button) v.findViewById(R.id.caseCancel);
		caseStop=(Button) v.findViewById(R.id.caseStop);
		cancel=(Button) v.findViewById(R.id.cancel);
		caseTitle=(TextView) v.findViewById(R.id.caseTitle);
		reBroadcast=(Button) v.findViewById(R.id.reBroadcast);
		switch (caseState) {
		case 1:
			caseTitle.setText("案件状态：未抢单");
			caseCancel.setVisibility(View.GONE);
			break;

		case 2:
			caseTitle.setText("案件状态：抢单终止");
			caseStop.setVisibility(View.GONE);
			caseCancel.setVisibility(View.GONE);
			break;

		case 3:
			caseTitle.setText("案件状态：已抢单");
		caseStop.setVisibility(View.GONE);
			break;

		case 4:
			caseTitle.setText("案件状态：放弃抢单");
			caseStop.setVisibility(View.GONE);
			caseCancel.setVisibility(View.GONE);
			break;

		case 5:
			caseTitle.setText("案件状态：注销");
			caseStop.setVisibility(View.GONE);
			caseCancel.setVisibility(View.GONE);
			break;

		case 6:
			caseTitle.setText("案件状态：已完成");
			caseStop.setVisibility(View.GONE);
			caseCancel.setVisibility(View.GONE);
			break;

		default:
			break;
		}
		cancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dismiss();
			}
		});

		caseCancel.setOnClickListener(cancelClick);
		caseStop.setOnClickListener(stopClick);
		reBroadcast.setOnClickListener(reBroadcastClick);
		this.setContentView(v);
		this.setWidth(LayoutParams.MATCH_PARENT);
		this.setHeight(LayoutParams.WRAP_CONTENT);
		this.setFocusable(true);
		this.setAnimationStyle(android.R.style.Animation);
		ColorDrawable dw=new ColorDrawable(0xb0000000);
		this.setBackgroundDrawable(dw);
		v.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				int height=v.findViewById(R.id.pop_task).getTop();
				int y=(int) event.getY();
				if(event.getAction()==MotionEvent.ACTION_UP){
					if(y<height){
						dismiss();
					}
				}
				return true;
			}
		});
	}










}
